<template>
  <div>
    <div class="clearfix">
      <el-menu
        :default-active="activeIndex"
        class="el-menu-demo"
        mode="horizontal"
        @select="handleSelect"
        background-color="#2a2d2f"
        text-color="#fff"
        active-text-color="#ffd04b"
        style="border-bottom: none;display: inline-block;float: left">
        <el-menu-item index="1">全部费用</el-menu-item>
        <el-menu-item index="2">已发生的费用</el-menu-item>
        <el-menu-item index="3">我负责的费用</el-menu-item>
        <el-menu-item index="4">被退回的费用</el-menu-item>
      </el-menu>
      <el-button type="primary" style="float: right;border-radius: 0 4px 4px 0;margin-top: 10px;margin-right: 15px;" @click="SearchCost">搜索</el-button>
      <el-input
        placeholder="搜索任务编号来查询费用"
        v-model="Search"
        prefix-icon="el-icon-search"
        clearable
        class="searchMission">
      </el-input>
    </div>
    <div style="background-color: white; margin: 20px;padding:20px;height: 500px;" >
      <el-table
        :data="PayTable"
        style="width: 100%;"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}">
        <el-table-column
          prop="name"
          label="标题"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="finance"
          label="财务科目"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="budget"
          label="预算金额"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="execute"
          label="执行金额"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="happenDate"
          label="发生日期"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="payDate"
          label="付款日期"
          show-overflow-tooltip>
        </el-table-column>
      </el-table>
      <div style="margin-top: 10px;text-align: center">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 6, 7, 8]"
          :page-size="PageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  const axios = require('axios');
  export default {
    name: "payManagement",
    data() {
      return {
        activeIndex : '1',

        //分页数据
        currentPage: 1,
        total: 0,
        PageSize: 5,
        currentTable: 1,

        Search: '',

        PayTable:[],
      }
    },
    created() {
      this.$axios.all([
        axios.post('/getAllCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}),
        axios.post("/getProjectMessage",{"id":this.$route.params.id}),
      ]).then(this.$axios.spread((res1, res2) => {
        this.PayTable = res1.data.list;
        this.total = res1.data.total;
        // console.log(res2);
        this.$parent.projectName = res2.data.projectName;
        this.$parent.topStatus = res2.data.topStatus;
        this.$parent.creatorId = res2.data.creatorId;
        this.$parent.principalId = res2.data.principalId;

      }))

    },
    methods: {
      handleSelect(key) {
        if(key == 1){
          axios.post('/getAllCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 1;
          })
        }else if(key == 2){
          axios.post('/getHappenCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 2;
          })
        }else if(key == 3){
          axios.post('/getMyCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"principal_id":window.localStorage.getItem("id")}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 3;
          })
        }
        else{
          axios.post('/getBackCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 4;
          })
        }
      },
      handleSizeChange(val) {
        this.PageSize = val;
        if(this.currentTable = 1){
          axios.post('/getAllCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 1;
          })
        }else if(this.currentTable = 2){
          axios.post('/getHappenCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 2;
          })
        }else if(this.currentTable = 3){
          axios.post('/getMyCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"principal_id":window.localStorage.getItem("id")}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 3;
          })
        }else if(this.currentTable = 4){
          axios.post('/getBackCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 4;
          })}
        else{
          axios.post('/getSearchProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"missionId":this.Search}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 5;
          })
        }
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        if(this.currentTable = 1){
          axios.post('/getAllCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 1;
          })
        }else if(this.currentTable = 2){
          axios.post('/getHappenCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 2;
          })
        }else if(this.currentTable = 3){
          axios.post('/getMyCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"principal_id":window.localStorage.getItem("id")}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 3;
          })
        }else if(this.currentTable = 4){
          axios.post('/getBackCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 4;
          })}
        else{
          axios.post('/getSearchCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"missionId":this.Search}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 5;
          })
        }
      },
      SearchCost(){
        let reg = /^\d+$|^\d+[.]?\d+$/;
        if(this.Search == ""){
          this.$message.error("搜索不能为空")
        }else if(!reg.test(this.Search)) {
          this.$message.error("只能输入数字编号搜索")
        }else{
          axios.post('/getSearchCost', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"missionId":this.Search}).then(res => {
            this.PayTable = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 5;
          })
        }
      }
    }
  }
</script>

<style scoped>

</style>
